#include <iostream>
#include<string.h>

using namespace std;


//点
class Point
{
    public:
        // 使用有参数构造函数，并使用初始化列表初始化 x，y
        Point(double x = 0, double y = 0) : x(x), y(y) {}
        // 拷贝构造函数
        Point(const Point & p){
            this->x = p.x;
            this->y = p.y;
        }
        // 析构函数，由于没有申请内存，析构函数中不需要做什么
        ~Point() {}
        // x, y 绑定的成成员函数
        void setPoint(const Point &p) {
            this->x = p.x;
            this->y = p.y;
        }
        void setPoint(double x, double y) {
            this->x = x;
            this->y = y;
        }
        void setX(double x) { this->x = x; }
        double getX() { return x; }
        void setY(double y) { this->y = y; }
        double getY() { return y; }
    private:
        double x;
        double y;
}; 

//地图类
class Graph
{
    public:
        // 构造函数
        Graph(int x,int y);
         // 拷贝构造函数
        Graph (const Graph & p);
        //析构函数
        ~Graph();
        //输入地图
        void map1(char **w,int x,int y);
        //输出地图
        void show();
        char **getmap();
        int getlen1();
        int getlen2();
    private:
        int len1_max;//地图最大长度
        int len2_max;//地图最大宽度
        int len1;//地图实际长度
        int len2;//地图实际宽度
        char ** map_a;//地图数组指针
};

Graph::Graph(int x,int y){
    if (x && y == 0) map_a = NULL;
    else{
        len1_max = x;
        len2_max = y;
        len1 = 0;
        len2 = 0;
        map_a = new char *[len1_max];
        for(int i = 0; i < len1_max; i++){
            map_a[i] = new char [len2_max];
        }
    }
}
Graph::Graph (const Graph & p){
    if(map_a) {
        for(int i = 0; i <len1; i++)
            delete[]map_a[i];
        delete []map_a;
    }
    len1_max = p.len1_max;
    len2_max = p.len2_max;
    len1 = p.len1;
    len2 = p.len2;
    memcpy(map_a,p.map_a,sizeof(char)*len1_max*len2_max);
}
Graph::~Graph(){
    for(int i = 0; i <len1; i++)
        delete[]map_a[i];
    delete []map_a;
}

void Graph::map1(char **w,int x,int y){
    if(x>len1_max||y>len2_max) cout<<"输入地图数据有误"<<endl;
    else{
        len1 = x;
        len2 = y;
        memcpy(map_a,w,sizeof(char)*x*y);
    }
        
}

void Graph::show(){
    cout<<"地图数据如下:"<<endl;
    int i,j;
    for(i=0;i<len1;i++){
        for(j=0;j<len2;j++)
            cout<<map_a[i][j];
        cout<<endl;
    }
}

char **Graph::getmap(){
    return map_a;
}
int Graph::getlen1(){
    return len1;
}
int Graph::getlen2(){
    return len2;
}
//坦克类
class tank{
    public:
        tank() {}
        tank(int x = 0, int y = 0, int direction = 0) : x(x), y(y), direction(0){
            this->x=x;
            this->y=y;
            this->direction=direction;
        } 
        tank(const tank &p){
            this->x=p.x;
            this->y=p.y;
            this->direction=direction;
        }
        ~tank(){}
        int getX(){
            return this->x;
        }
        int getY(){
            return this->y;
        }
        void down(char **map){
            if(this->x-1<0||map[this->x-1][this->y]=='1') cout<<"下移错误:"<<" ";
            else 
            {
                this->x--;
                cout<<"下移"<<" ";
            }
        }
        void up(char **map,int c){
            if(this->x+1>c||map[this->x+1][this->y]=='1') cout<<"上移错误:"<<" ";
            else 
            {
                this->x++;
                cout<<"上移"<<" ";
            }
        }
        void right(char **map,int d){
            if(this->y+1>d||map[this->x][this->y+1]=='1') cout<<"右移错误:"<<" ";
            else {
                this->y++;
                cout<<"右移"<<" ";
            }
        }
        void left(char **map){
            if(this->y-1<0||map[this->x][this->y-1]=='1') cout<<"左移错误:"<<" ";
            else {
                this->y--;
                cout<<"左移"<<" ";
            }
        }
        void show(){
            cout<<"("<<this->x<<","<<this->y<<")"<<endl;
        }
    private:
        int x,y;//坦克位置坐标(x,y)
        int direction;
};

void move(Graph & p,tank & f){
    int z;
    for(int i=0;i<100;i++)
    {
        cin>>z;
        if(z==1) f.left(p.getmap());
        else if(z==2) f.right(p.getmap(),p.getlen2());
        else if(z==3) f.up(p.getmap(),p.getlen1());
        else if(z==4) f.down(p.getmap());
        else if(z==5)  break;
        f.show();
    }
}

int main()
{
    Graph t(10,10);
    char *map[10]={"000000000","000111000","110110000","000000011","110000000",
                     "000000111","011100000","000000000","111110000","111100000"};
    t.map1(map,10,10);
    t.show();
    tank m(0,2,0);
    //坦克行走(1左2右3上4下 5停止)
    cout<<"开始移动坦克"<<endl;
    move(t,m);
    return 0;
}